<?php

# database connection
include '../lib5/pdoExt.php';
include 'dbConn.php';

# objlib library code
include '../lib5/Util.php';
include '../lib5/Object.php';
include '../lib5/JoinerRelation.php';
include '../lib5/SortedJoinerRelation.php';
include '../lib5/KeyRelation.php';
include '../lib5/SortedKeyRelation.php';
include '../lib5/Query.php';
include '../lib5/Node.php';


# englopya library code
include_once "../Components/Component.php";
include_once "../Components/ComponentContainer.php";
foreach (glob ('../Components/*.php') as $componentFile) {
        include_once ($componentFile);
}

# englopya Relations
foreach (glob ('../Relations/*.php') as $relationFile) {
        include_once ($relationFile);
}

$dbh->exec ('drop table Nav');
$dbh->exec ('drop table NavHasNav');
$dbh->exec ('delete from Template where title = "Navigation Template 1"');

Component::updateView ();

$navTempl = new Template (false, 'Navigation Template 1');
$navTempl->content = <<<TEMPL
<?php foreach (\$this->children as \$child) { ?>
<a href="/index.php/<?php echo \$child->navURL ?>"><?php echo \$child->title ?></a><br>
<?php }; ?>
TEMPL;
$navTempl->save();

$rootNav = new Nav (false, false, array (
	'title'      => 'MainNav',
	'URL'        => 'Nav1',
	'templateId' => $navTempl->id(),
	'styleId'    => 1
));
$rootNav->save();

$page = new Page (1);
$article = new Article (1);

$subNav = new Nav (false, false, array (
	'title'      => 'SubNav1',
	'URL'        => 'SubNav1',
	'templateId' => $navTempl->id(),
	'styleId'    => 1
));
$subNav->assignComponent ($page);

$rootNav->assignChild ( $subNav );

$subNav = new Nav (false, false, array (
	'title'      => 'SubNav2',
	'URL'        => 'SubNav2',
	'templateId' => $navTempl->id(),
	'styleId'    => 1
));
$subNav->assignComponent ($article);

$rootNav->assignChild ( $subNav );

$rootNav->render ();

?>